package com.haoji.upload.common.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @program: upload
 * @description: ApplicationContext容器工具类MD5Util
 * @author: xiaolei
 * @create: 2021-04-19 15:30
 **/
public class ApplicationHelper implements ApplicationContextAware {

    private static ApplicationContext app;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        app = applicationContext;
    }

    public static <T> T popBean(Class<T> clazz) {
        if (app == null) {
            return null;
        }
        return app.getBean(clazz);
    }

    public static <T> T popBean(String name, Class<T> clazz) {
        if (app == null) {
            return null;
        }
        return app.getBean(name, clazz);
    }

}
